package com.ruoyi.ma.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.ma.domain.MaMaterialMeasureSingle;
import com.ruoyi.ma.domain.vo.MaMaterialProgressDetailsVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ma.domain.vo.MaMaterialMeasureSingleVo;
import com.ruoyi.ma.domain.bo.MaMaterialMeasureSingleBo;
import com.ruoyi.ma.service.IMaMaterialMeasureSingleService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 材料计量单
 *
 * @author llb
 * @date 2024-11-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ma/materialMeasureSingle")
public class MaMaterialMeasureSingleController extends BaseController {

    private final IMaMaterialMeasureSingleService iMaMaterialMeasureSingleService;

    /**
     * 查询材料计量单列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<MaMaterialMeasureSingleVo> list(MaMaterialMeasureSingleBo bo, PageQuery pageQuery) {
        return iMaMaterialMeasureSingleService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出材料计量单列表
     */
    @SaCheckLogin
    @Log(title = "材料计量单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MaMaterialMeasureSingleBo bo, HttpServletResponse response) {
        List<MaMaterialMeasureSingleVo> list = iMaMaterialMeasureSingleService.queryList(bo);
        ExcelUtil.exportExcel(list, "材料计量单", MaMaterialMeasureSingleVo.class, response);
    }

    /**
     * 获取材料计量单详细信息
     *
     * @param measureSingleId 主键
     */
    @SaCheckLogin
    @GetMapping("/{measureSingleId}")
    public R<MaMaterialMeasureSingleVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long measureSingleId) {
        return R.ok(iMaMaterialMeasureSingleService.queryById(measureSingleId));
    }

    /**
     * 新增材料计量单
     */
    @SaCheckLogin
    @Log(title = "材料计量单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MaMaterialMeasureSingleBo bo) {
        return toAjax(iMaMaterialMeasureSingleService.insertByBo(bo));
    }

    /**
     * 修改材料计量单
     */
    @SaCheckLogin
    @Log(title = "材料计量单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MaMaterialMeasureSingleBo bo) {
        return toAjax(iMaMaterialMeasureSingleService.updateByBo(bo));
    }

    /**
     * 删除材料计量单
     *
     * @param measureSingleIds 主键串
     */
    @SaCheckLogin
    @Log(title = "材料计量单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{measureSingleIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] measureSingleIds) {
        return toAjax(iMaMaterialMeasureSingleService.deleteWithValidByIds(Arrays.asList(measureSingleIds), true));
    }

    // 获取签收明细
    @SaCheckLogin
    @GetMapping("/progressDetails")
    public R<List<MaMaterialMeasureSingle>> progressDetails(MaMaterialMeasureSingleBo bo) {
        return R.ok(iMaMaterialMeasureSingleService.progressDetails(bo));
    }

}
